#ifndef ADAPTATION_H
#define ADAPTATION_H


#include <Box2D/Box2D.h>

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <functional>   
#include <string>
#include <algorithm>
#include <functional>
#include "RecordInfo.h"
#include "Finger.h"
#include "Phase.h"
#include "ActualInfo.h"

class Adaptation
{
public:
	enum
	{
		e_shiftingUpAdaptationBit = 0x0001,
		e_shiftingDownAdaptationBit = 0x0002,
		e_shiftingLeftAdaptationBit = 0x0004,
		e_shiftingRightAdaptationBit = 0x0008,
		e_generalAdaptationBit = 0x0010
	};
	
	class RecordInfo_flag_equ : public std::unary_function<RecordInfo, bool>
	{
	public:
		std::string flag;
		explicit RecordInfo_flag_equ(const std::string s):flag(s){};
		bool operator ()(const RecordInfo& ri){return !ri.flag.compare(flag);}
	};
	
	Adaptation(int32 flag);

	b2Vec2 ShiftingUpAdaptation(int& timeStep, bool isTouched, std::vector<RecordInfo>& recordInfos, Finger* finger);
	b2Vec2 ShiftingDownAdaptation(int& timeStep, bool isTouched, std::vector<RecordInfo>& recordInfos, Finger* finger);
	b2Vec2 ShiftingLeftAdaptation(int& timeStep, bool isTouched, std::vector<RecordInfo>& recordInfos, Finger* finger);
	b2Vec2 ShiftingRightAdaptation(int& timeStep, bool isTouched, std::vector<RecordInfo>& recordInfos, Finger* finger);
	b2Vec2 MyAdaptation(int& timeStep, bool isTouched, std::vector<RecordInfo>& recordInfos, std::vector<ActualInfo>& actualInfos, std::vector<Phase>& phases, Finger* finger);
	b2Vec2 GeneralAdaptation(int& timeStep, bool isTouched, std::vector<RecordInfo>& recordInfos, std::vector<ActualInfo>& actualInfos, std::vector<Phase>& phases, Finger* finger);
	b2Vec2 Fb_Mul_Diff(float32 (*array1)[6], float32* array2);
	b2Vec2 MultiplyWithAMP(float32 aMatrix[], float32 bMatrix[]);
	int PhaseTransition(int currentPhase);
	bool isShiftingAdaptationStart();
	bool isShiftingAdaptationEnd();
	static float32 m_fbArray[2][6];
	static float32 fbArray[12];
private:
	bool m_adaptationStart;
	bool m_adaptationEnd;
	bool m_trialStart;
	bool m_trialEnd;
	bool m_extensionApproach;
	bool m_extensionTipping;
	int32 m_adaptationFlag;
	int m_currentPhase;
	int m_totalPhase;
	std::vector<std::vector<float32>> m_fbMatrix;
};
#endif